<?php
 $db =& JFactory::getDBO(); 
 $query = "SELECT * FROM #__users";
 $db->setQuery( $query );
 $row = $db->loadObjectList();
 $temp=0;
 for($i=0;$i<count($row);$i++)
 {
 	if($row[$i]->email==$_GET['email'])
 	 $temp=1;
 }
 if($temp==0)
  echo "<span style='color:red;'>Indtast venligst din e-mail-adresse. Denne adresse er forkert</span>";
 else
 {
	 /*
	if(trim($_GET['passw'])=='') { echo "<span style='color:red;'>Indtast venligst din Adgangskode</span>"; 
		exit();
	}
	 */
	 
 	jimport('joomla.application.component.modelform');
    jimport('joomla.event.dispatcher');
 	$query = "SELECT * FROM #__users where email='".$_GET['email']."'";
    $db->setQuery( $query );
    $row = $db->loadObject();
    $id_user=$row->id;
    //echo $id_user;
    $user = JUser::getInstance($id_user);
    // Generate the new password hash.
		//$salt		= JUserHelper::genRandomPassword(32);
		//$password_new		= JUserHelper::genRandomPassword(32);
		//$password_new		= $_GET['passw'];
		$password_new		= JUserHelper::genRandomPassword(32);
		//echo $password;
		//$crypted	= JUserHelper::getCryptedPassword($password_new, $salt);
		//$password	= $crypted.':'.$salt;
        //$query = "update #__users set password='".$password."' where email='".$_GET[email]."'";   
        //$db->setQuery( $query );
        //$db->query();
		// Update the user object.
		//$user->password			= $password;
		//$user->activation		= '';
		//$user->password_clear	= "nambu";
		//$user->save(true);
		$config	= JFactory::getConfig();
        $data['fromname']	= $config->get('fromname');
		$data['mailfrom']	= $config->get('mailfrom');
		$data['sitename']	= $config->get('sitename');
		$subject="Nulstille adgangskoden";
		$body ="Firma Navn : " . $row->username ." <br/>";
		$body .="Nye kodeord er : $password_new <br/>
		Klik på linket <a href='".JURI::root()."index.php?option=com_users&task=reset.completepassword&id_user=".$id_user."&pass=".$password_new."'>her</a> for at nulstille adgangskode";
		$body.= "<br/><br/>Med venlig hilsen,
					<br/><a href='http://www.3malertilbud.dk'><b>3malertilbud.dk</b></a
					<br/><a href='mailto:info@3malertilbud.dk'>info@3malertilbud.dk</a>";
		$body.= "<br/><img src='".JURI::root()."/templates/3dmaler/img/email_logo_footer.jpg'></img>";	
			
		JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $_GET['email'], $subject, $body,1);
        echo "<span style='color:red;'><strong>genstarte adgangskoden var vellykket. en ny adgangskode blev sendt til din e-mail</strong></span>";
 }  
 exit();
?>